import math
import numpy as np
import matplotlib as plt

def fx(x):
    return math.exp(x)

def simp(a,b,eps):
    n = 2
    h = (b-a)/n
    T1 = 0.5 * h * (fx(a) + fx(b))
    tol = 1
    while tol > eps:
        T0 = T1
        n = 2 * n
        h = (b-a)/n
        x = []
        for i in range(n):
            x.append(a + i * h)
        y = []
        for i in range(n):
            y.append(fx(x[i]))
        y2=0.00
        for i in range(n-1):
            if i > 0:
                y2 = y2 + y[i]
        T1 = h * (0.5 * y[0] + y2 + 0.5 * y [n-1])
        tol = abs(T1 -T0)
    return T1
print(simp(0,math.pi,0.00001))